﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="JsSQL数据库创建表的SQL生成 NET的类型.aspx.cs" Inherits="js组件_JsSQL数据库创建表的SQL生成_NET的类型"   %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        #TextArea1
        {
            width: 1002px;
            height: 181px;
        }
        #ItempCont
        {
            width: 1007px;
            height: 20px;
        }
        #test
        {
            width: 1003px;
            height: 252px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <script language="javascript" type="text/javascript">
 //edit by skybot
 //http://www.qlili.com/
 //2008-1-29
 
    ///<summary>
    ///添加新记录
    ///</summary>
    var  Sql_insert="";
    
    var  sql_insert_fun="";//实现添加的方法

    ///<summary>
    ///更新记录
    ///</summary
    var  Sql_Update="";
  var  sql_Update_fun="";//实现更新记录的方法
    
    
   ///<summary>
    ///删除记录
    ///</summary
    var  Sql_Del ="";
    
    ///数据库表的主键名
    var TableDataKey="";
    
    ///数据库表的名
    var TableName ="";

    ///用于通用操作类型的字符串
    var  TongClass="";
    
    String.prototype.upperFirstChar = function()
    {
        return this.replace(/^(\w)/,function($1){return $1.toUpperCase();});
    }
    
    String.prototype.lowerFirstChar = function()
    {
        return this.replace(/^(\w)/,function($1){return $1.toLowerCase();});
    }

    var ConvertDbTypeToCSType = {
                    "bigint":"long",
                    "binary":"byte[]",
                    "bit":"bool",
                    "char":"char",
                    "datetime":"DateTime",
                    "decimal":"decimal",
                    //"float":"float",
                    "float":"double",//float在指定为 float 反射时出错 现在改为 double
                    "image":"byte[]",
                    "int":"int",
                    "money":"string",
                    "nchar":"char",
                    "ntext":"string",
                    "numeric":"decimal",
                    "nvarchar":"string",
                    "real":"Single", //real 在指定为 string 反射时出错 现在改为double 但double 会出错 ,所有现在只能用string了 或 single 使用 single只能最多输入7位数字
                    "smalldatetime":"DateTime",
                    "smallint":"int",
                    "smallmoney":"string",
                    "sql_variant":"string",
                    "sysname":"string",
                    "text":"string",
                    "timestamp":"DateTime",
                    "tinyint":"int",
                    "uniqueidentifier":"string",
                    "varbinary":"byte[]",
                    "varchar":"string"
                    
                    /*
                    对应表
                     switch(type.tolower())   
        {   
          case   "int":   
            reval=   "int32";   
            break;   
          case   "text":   
            reval=   "string";   
            break;   
          case   "bigint":   
            reval=   "int64";   
            break;   
          case   "binary":   
            reval=   "system.byte[]";   
            break;   
          case   "bit":   
            reval=   "boolean";   
            break;   
          case   "char":   
            reval=   "string";   
            break;   
          case   "datetime":   
            reval=   "system.datetime";   
            break;   
          case   "decimal":   
            reval=   "system.decimal";   
            break;   
          case   "float":   
            reval=   "system.double";   
            break;   
          case   "image":   
            reval=   "system.byte[]";   
            break;   
          case   "money":   
            reval=   "system.decimal";   
            break;   
          case   "nchar":   
            reval=   "string";   
            break;   
          case   "ntext":   
            reval=   "string";   
            break;   
          case   "numeric":   
            reval=   "system.decimal";   
            break;   
          case   "nvarchar":   
            reval=   "string";   
            break;   
          case   "real":   
            reval=   "system.single";   
            break;   
          case   "smalldatetime":   
            reval=   "system.datetime";   
            break;   
          case   "smallint":   
            reval=   "int16";   
            break;   
          case   "smallmoney":   
            reval=   "system.decimal";   
            break;   
          case   "timestamp":   
            reval=   "system.datetime";   
            break;   
          case   "tinyint":   
            reval=   "system.byte";   
            break;   
          case   "uniqueidentifier":   
            reval=   "system.guid";   
            break;   
          case   "varbinary":   
            reval=   "system.byte[]";   
            break;   
          case   "varchar":   
            reval=   "string";   
            break;   
          case   "variant":   
            reval="object";   
            break;   
          default:   
            reval=   "string";   
            break;   

                    */
                    };
        //类型的默认值
        var Types_DefalutValue = {
                "long":"0",
                "byte[]":"new byte[1]",
                "bool":"false",
                "char":"' '",
                "DateTime":"DateTime.Now",
                "double":"0",
                "decimal":"0",
                "float":"0",
                "Single":"0",
                "int":"0",
                "string":"\"\""
                };
    function CsFileStream()
    {
        this.ms = new Array();
        this.tabNum = 0;
        
        this.getTabs = function()
        {
            var arr = new Array();
            arr.length = this.tabNum + 1;
            return arr.join("\t");
        }
    }
    
    CsFileStream.prototype.append = function()
    {
        var str =  arguments[0];
        if(str instanceof Array)
        {
            str = str.join("");
        }
        if(this.tabNum > 0)
        {
            var tabs = this.getTabs();
            var tmpStr = str.replace(/\n/g,"\n" + tabs);
            this.ms[this.ms.length] = tmpStr;
        }
        else
        {
            this.ms[this.ms.length] = str;
        }
    }
    
    CsFileStream.prototype.addTab = function()
    {
        this.tabNum ++;
        if(this.ms.length > 0)
        {
            this.ms[this.ms.length - 1] = this.ms[this.ms.length - 1].replace(/\n\t*$/gm,'\n' +  this.getTabs());
        }
    }    
    
    CsFileStream.prototype.delTab = function()
    {
        this.tabNum --;
        if(this.ms.length > 0)
        {
            this.ms[this.ms.length - 1] = this.ms[this.ms.length - 1].replace(/\n\t*$/gm, '\n' +  this.getTabs());
        }
    }    

    CsFileStream.prototype.toString = function()
    {
        return this.ms.join("");
    }    
    
    ///找到生成操作方法的模板，进行生成操作
    CsFileStream.prototype.Buid_DataOPeration= function(ClassName,InserString ,UpdateString,ConvertToObject,DataKey,Attribs)//新增，更新，查询 //转换成对象 , DataKey 主键,  Attribs 表中的字段
                                              {
                                                 var Att_Parames = new Array();//参数
                                                 var Att_Atribs = new Array();//属性 字段的名字                                         
                                                 var ClassString =document.getElementById("ItempCont").value;//得到模板
                                                 var temp_text="";
                                                 //initalize 
                                                 for(i=0; i<Attribs.split(",").length;i++)
                                                 { 
                                                    if(Attribs.split(",")[i]!="")
                                                    {
                                                        Att_Parames[i]="@"+ Attribs.split(",")[i] ;
                                                        Att_Atribs[i]=Attribs.split(",")[i] ;
                                                    }
                                                 }
                                                 

                                                 
                                                 ClassString =  ClassString.replace(/##ClassName##/g,ClassName);
                                                 
                                                 //开始进行各们方法的提换
                                                 //insert 
                                                  ClassString = ClassString.replace("//##Operate_inser##",InserString.replace("TextData.MySql","MySql")+"\r\n\t\t\t return true;");
                                                 //Updata
                                                 ClassString = ClassString.replace("//##Operate_update##",UpdateString.replace("TextData.MySql","MySql")+"\r\n\t\t\t return true;");
                                                 
                                                 //开始更新查询
                                                  
                                                   /// 传入 实例化的对象的主键值 此对象一定要指定主键
                                                   //##Operate_Operate_Select_Obj##
                                                   temp_text+="\r\n\t\t"+ "MyDa.SelectCommand.CommandText = \"select * from  ["+ClassName+"] where  ["+DataKey+"] = @"+DataKey+"  \"+OrderBy;";
                                                   temp_text+="\r\n\t\t"+ "MyDa.SelectCommand.Parameters.Add(\"@"+DataKey+"\",DataTable_Obj."+DataKey+");"
                                                   ClassString = ClassString.replace("//##Operate_Operate_Select_Obj##",temp_text);
                                                   temp_text="";
                                                   
                                                  // 传入一个 ID 值 用于得这个ID 值下的所有 数据
                                                  //##Operate_Operate_Select_ID##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select * from ["+ClassName+"] where  ["+DataKey+"] =\"+ID+\"  \"+OrderBy;";                                                  
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_ID##",temp_text);
                                                  temp_text="";
                                                  
                                                  ///  传入字段名得到这个字段在表里的记录,只有一个字段 
                                                  ///  返回 DataSet
                                                  //##Operate_Operate_Select_IDAndCoulmnName##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select \"+CoulmnName+\" from ["+ClassName+"] where  ["+DataKey+"] =\"+ID+\"  \"+OrderBy;";                                                  
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_IDAndCoulmnName##",temp_text);
                                                  temp_text="";
                                                  
                                                 /// 字段名 返回一个字段的值 调用条数
                                                  //##Operate_Operate_Select_CoulmnNameAndRecordNum##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select Top (\"+RecordNum+\")  \"+CoulmnName+\" from  ["+ClassName+"]     \"+OrderBy;";
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_CoulmnNameAndRecordNum##",temp_text);
                                                  temp_text="";
                                                  
                                                  /// 传入字段集合 返回条数据
                                                  //##Operate_Operate_Select_CoulmnName[]AndRecordNum##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select top (\"+RecordNum+\") \"+Cloumn+\" from  ["+ClassName+"]    \"+OrderBy;";
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_CoulmnName[]AndRecordNum##",temp_text);
                                                  temp_text="";
                                                  
                                                  //传入字段名得到这个字段在表里的记录,只有一个字段 
                                                  //##Operate_Operate_Select_CoulmnNameAndRecordNum_Where##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select Top (\"+RecordNum+\")  \"+CoulmnName+\" from  ["+ClassName+"]   where \"+Where+\"  \"+OrderBy;";
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_CoulmnNameAndRecordNum_Where##",temp_text);
                                                  temp_text="";
                                                  
                                                  //传入字段集合 返回条数据
                                                  //##Operate_Operate_Select_CoulmnName[]AndRecordNum_where##
                                                  temp_text = "MyDa.SelectCommand.CommandText = \"select top (\"+RecordNum+\") \"+Cloumn+\" from  ["+ClassName+"]   where \"+Where+\"   \"+OrderBy;";
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_CoulmnName[]AndRecordNum_where##",temp_text);
                                                  temp_text="";
                                                  
                                                 // 执行SQL语句 返回dataSet
                                                 //##Operate_Operate_Select_Sql##
                                                  temp_text = "MyDa.SelectCommand.CommandText =Sql;";
                                                  ClassString = ClassString.replace("//##Operate_Operate_Select_Sql##",temp_text);
                                                  temp_text="";
                                                  
                                                  //执行转换成对象
                                                  //##Operate_Operate_Select_Sql##
                                                 temp_text = ConvertToObject;
                                                  ClassString = ClassString.replace("//##ConvertToObject##",temp_text);
                                                  temp_text="";
                                                 
                                                 
                                             return     ClassString
                                              }
    
    function buildCsFromSql(strSql)
    {
        var tableName = strSql.match(/table\s+\[([^\]]+)\]/i)[1];
        var column = [];
        var rgx = /\[([^\]]+)\]\s+\[([^\]]+)\]/gi;
        
        var DataKeyregx=/CLUSTERED\s{0,}\(\s{0,}.([^\]]+)/;//主键
        var DataKeyName =DataKeyregx.exec(strSql)[1];//主键
        TableDataKey = DataKeyName;//主键名
        TableName = tableName;//表名
        var arr;
        while((arr = rgx.exec(strSql)) != null)
        {
            column[arr[1]] = {};
            column[arr[1]].name=arr[1];
                   
            column[arr[1]].dbtype=arr[2];
          
            column[arr[1]].cstype=ConvertDbTypeToCSType[arr[2]];
            
           // column[arr[2]].cstype;
        }
        
       // rgx = /N'MS_Description',\s+N'([^']+)'.+N'([^']+)'$/gim;//sql 2000
       rgx =/N'MS_Description',\s+@value=N'([^']+)'.+N'([^']+)'$/gim;//sql 2005
        while((arr = rgx.exec(strSql)) != null)
        {
            column[arr[2]].dbdesc=arr[1];
      
           
        }
        
        var cs = new CsFileStream();
        cs.append("/// <summary>\n");
        cs.append(["/// ",tableName.upperFirstChar(),"数据库操作类。\n"]);
        cs.append("/// </summary>\n");
        cs.append(["public class Data_",tableName.upperFirstChar(),"\n"]);
        cs.append("{\n");
        
        cs.addTab();
        
         
               //用于记录的参数
   var TabArr = new Array(); 
    TabArr.length=0;
        for(var i in column)
        {
            //私有成员
            cs.append(["private ",column[i].cstype," ", column[i].name.lowerFirstChar(),"_ = "+Types_DefalutValue[column[i].cstype]+";\n"]);
            cs.append("/// <summary>\n");
            cs.append(["/// ",column[i].dbdesc]);
            cs.append("\n/// </summary>\n");
            cs.append(["public ",column[i].cstype," ", column[i].name.upperFirstChar(),"\n"]);
            cs.append("{\n");
            cs.addTab();
            cs.append(["get{ return ",column[i].name.lowerFirstChar(),"_ ; }\n"]);
            cs.append(["set{ ",column[i].name.lowerFirstChar(),"_ = value; }\n"]);
            cs.delTab();
            cs.append("}\n");
            cs.append("public static string _"+column[i].name+"=\""+column[i].name+"\";\n");//添加字段
            
            TabArr[i] = new Array(column[i].name,column[i].cstype);//在BulidSqlOperate 中便用，现在给值
        
        }
        cs.delTab();
        cs.append("}\n");
        
        ///创建操作方法 包括 添加，删除，修改 选择
        //创建操作类BulidSqlOperate
        //insert 

        Sql_insert ="\""+  "INSERT INTO ["+tableName.upperFirstChar()+"] (\r\n\t\t\t";
         var sql_insert_paramestr ="";//用于保存生成SQL语句的字段参数 ,如 @xx,@oo,
        //update
        Sql_Update = "\""+  " UPDATE ["+tableName.upperFirstChar()+"] Set \r\n\t\t\t";
        
        var sql_ParameStr ="";//用于Sql的参数 生成 C# 代码
        var sql_temp_str ="";//生成方法临时变量
        
        var sql_UpdateParamestr="";//用于Sql的参数 生成 C# 代码 update
        
        var sql_Attribs="";//得到这个表的所有的 字段
         
         ///用于数据转换成对象
        var DataTOObject=""; 
        for(var i in TabArr)
        {
           
                       
            ///不是主键
            if(DataKeyName!=TabArr[i][0])
            {
                Sql_insert+=TabArr[i][0]+"\r\n\t\t\t,";//insert
                sql_insert_paramestr+="@"+TabArr[i][0]+"\r\n\t\t\t,";//insert
                Sql_Update+=TabArr[i][0]+"="+"@"+TabArr[i][0] +"\r\n\t\t\t,";//update
                sql_temp_str+="\r\n Cmd.Parameters.Add(new SqlParameter(\""+"@"+TabArr[i][0]+"\", t."+TabArr[i][0]+"));";//set parames C#
                
                //sql 字段和字段的类型
                sql_Attribs +=TabArr[i][0]+",";
            }
                            
                ///用于数据转换成对象
                DataTOObject+="Mydato."+TabArr[i][0]+"=("+TabArr[i][1]+")(Mydt.Rows[i][Data_"+tableName.upperFirstChar()+"._"+TabArr[i][0]+"].GetType().ToString() == System.DBNull.Value.GetType().ToString() ?"+Types_DefalutValue[column[i].cstype]+":Mydt.Rows[i][Data_"+tableName.upperFirstChar()+"._"+TabArr[i][0]+"]);\r\n";//转换对象

        }
       //删除后面的 ，
       Sql_insert =Sql_insert.substring(0,Sql_insert.length-1);
       sql_insert_paramestr=sql_insert_paramestr.substring(0,sql_insert_paramestr.length-1);
       Sql_Update = Sql_Update.substring(0,Sql_Update.length-1);
       sql_Attribs =  sql_Attribs.substring(0,sql_Attribs.length-1);

       

       
       
       //处理insert 
       Sql_insert+=")\r\n"  +"\""+  "values(\r\n\t\t\t";
       Sql_insert+=sql_insert_paramestr;
       Sql_insert+=")"       +"\"";
       
       //处理 Update
       Sql_Update+="\r\n\t\t\t";
       Sql_Update+="where ["+DataKeyName+"] = @"+DataKeyName+"\r\n\t\t\t";
       Sql_Update+=""       +"\"";

       
       //开始处理各个参数
       sql_ParameStr ="SqlCommand Cmd = new SqlCommand();\r\n";//用于Sql的参数 生成 C# 代码
       sql_ParameStr +="Cmd.CommandType = CommandType.Text;\r\n";
       sql_ParameStr+="Cmd.Connection = TextData.MySql;\r\n" ;
       sql_ParameStr+=" Cmd.CommandText = "+Sql_insert.replace(/\r\n/g,"\"+\r\n").replace(/\t\t\t/g,"\"\t\t\t")+";\r\n";
       sql_ParameStr+=sql_temp_str;
       sql_ParameStr+="\r\nCmd.ExecuteNonQuery();\r\n";
       
       //处理UPdata
       sql_UpdateParamestr +="SqlCommand Cmd = new SqlCommand();\r\n";//用于Sql的参数 生成 C# 代码
       sql_UpdateParamestr +="Cmd.CommandType = CommandType.Text;\r\n";
       sql_UpdateParamestr+="Cmd.Connection = TextData.MySql;\r\n" ;
       sql_UpdateParamestr+=" Cmd.CommandText = "+Sql_Update.replace(/\r\n/g,"\"+\r\n").replace(/\t\t\t/g,"\"\t\t\t")+";\r\n";
       sql_UpdateParamestr+=sql_temp_str+"\r\n Cmd.Parameters.Add(new SqlParameter(\""+"@"+DataKeyName+"\", t."+DataKeyName+"));";
       sql_UpdateParamestr+="\r\nCmd.ExecuteNonQuery();\r\n";
       
       
       //处理各函数
        //插入函数
       sql_insert_fun+="\r\n try{\t";
       sql_insert_fun+=sql_ParameStr;
       sql_insert_fun+="        }\r\n \t\t ";
       sql_insert_fun+="catch(Exception ex) \r\n\t\t";
       sql_insert_fun+="{\t\t\t ErrorInfo+=\"执行 "+tableName.upperFirstChar()+"表的添加操作时出现错误\"+ex.Message; \r\n\t\t";
       sql_insert_fun+="    return false;";
       sql_insert_fun+="\r\n  \t\t }";

      //更新函数
       sql_Update_fun+="\r\n try{\t";
       sql_Update_fun+=sql_UpdateParamestr;
       sql_Update_fun+="        }\r\n \t\t ";
       sql_Update_fun+="catch(Exception ex){\t\t\t ErrorInfo+=\"执行 "+tableName.upperFirstChar()+"表的更新操作时出现错误\"+ex.Message; \r\n\t\t";
       sql_Update_fun+="    return false;";
       sql_Update_fun+="\r\n  \t\t }";
      

        //开始处理SQL

       

       ///test
//        var divss =  document.createElement("div");
//        divss.innerHTML=DataTOObject.replace("\r\n","<br/>");
//        document.body.appendChild(divss);
//        sql_insert_paramestr ="";//clear();
        


         TabArr.length=0;
        if(DataKeyName==""||DataKeyName==undefined)
        {
          new   Error("此表无主键不能生成");
          
          return "";
        }
        else
        {
             TongClass = cs.toString();
             return cs.toString()+"\r\n"+cs.Buid_DataOPeration(tableName.upperFirstChar(),sql_insert_fun,sql_Update_fun,DataTOObject,DataKeyName,sql_Attribs);
        }

    }
    
   
    

    function go_buildCsFromSql()
    {
       document.getElementById("txtCs").value = buildCsFromSql(document.getElementById("txtSql").value.replace(/\[dbo\]\./g,""));
       //变为实现 IdataBaseTable的表
        TongClass = TongClass.substring(0,TongClass.length-3).replace("public class Data_"+TableName,"public class Data_"+TableName+":IDataBaseTable");

        ////定义表名
        TongClass+="\r\n   private string tableName = \""+TableName+"\"; \r\n";
        TongClass+="\r\n /// <summary> ";
        TongClass+="\r\n /// 数据库表名 ";
        TongClass+="\r\n /// </summary> ";
        TongClass+="\r\n public string TableName  ";
        TongClass+="\r\n {  ";
        TongClass+="\r\n     get { return tableName; }  ";
        TongClass+="\r\n     set { tableName = value; }  ";
        TongClass+="\r\n }  ";
        ///定义表主键
        TongClass+="\r\n   private string tableDataKey = \""+TableDataKey+"\"; ";
        TongClass+="\r\n /// <summary>";
        TongClass+="\r\n /// 数据库表主键名 ";
        TongClass+="\r\n /// </summary>";
        TongClass+="\r\n public string TableDataKey  ";
        TongClass+="\r\n {  ";
        TongClass+="\r\n     get { return tableDataKey; }  ";
        TongClass+="\r\n     set { tableDataKey = value; }  ";
        TongClass+="\r\n }  \r\n ";
        TongClass+="\r\n }  \r\n ";
        
        
        
        
       
       document.getElementById("TongClass").value = TongClass;
       TongClass="";
    }
    

</script>
<textarea id=txtSql style="width:73%;height:228px;">
USE [Cyesis]
GO
/****** 对象:  Table [dbo].[CX_link]    脚本日期: 01/29/2008 14:01:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[CX_link](
	[CX_link_id] [decimal](18, 0) IDENTITY(1,1) NOT NULL,
	[CX_Column_id] [decimal](18, 0) NULL CONSTRAINT [DF_CX_link_CX_Column_id]  DEFAULT ((0)),
	[CX_link_Name] [nvarchar](250) COLLATE Chinese_PRC_CI_AS NULL,
	[CX_link_LX] [nvarchar](2) COLLATE Chinese_PRC_CI_AS NULL CONSTRAINT [DF_CX_link_CX_link_LX]  DEFAULT (N'文字'),
	[CX_link_Pic] [nvarchar](500) COLLATE Chinese_PRC_CI_AS NULL,
	[CX_link_Cont] [nvarchar](4000) COLLATE Chinese_PRC_CI_AS NULL,
	[CX_link_Sort] [int] NULL CONSTRAINT [DF_CX_link_CX_link_Sort]  DEFAULT ((0)),
	[CX_link_linkUrl] [nvarchar](4000) COLLATE Chinese_PRC_CI_AS NOT NULL,
 CONSTRAINT [PK_CX_link] PRIMARY KEY CLUSTERED 
(
	[CX_link_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'自动编号' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_id'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'所属栏目' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_Column_id'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'站点名' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_Name'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'link类型 (文字 图片)' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_LX'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'图片link地址' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_Pic'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'站点说明' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_Cont'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'排序' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_Sort'

GO
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'LInk adderss ' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'CX_link', @level2type=N'COLUMN', @level2name=N'CX_link_linkUrl'

</textarea>
        <br />
<input type="button" value="生成" id="doit" onclick="go_buildCsFromSql()">
        <br />
<textarea id=txtCs style="width:73%;height:372px;">
</textarea>
        <br />
用于通用操作类型操作的表类型&nbsp; 用于实现IDataBaseTable 接口的表<br />
<textarea id=TongClass style="width:73%;height:133px;">
</textarea>
    </div>
    用于实现操作方法的类 模板<br />

    <p>
        <textarea id="ItempCont" name="ItempCont">#region 定义类型 定义类型  ##ClassName##  的操作方法 
    /// &lt;summary&gt;
    /// 用于对相应表 ##ClassName## 进行操作的类弄
    /// &lt;/summary&gt;
    /// &lt;typeparam name=&quot;T&quot;&gt;表类型对象&lt;/typeparam&gt;
    [System.ComponentModel.DataObject]
    public class Data_##ClassName##_QueryTable&lt;T&gt; : DataIQueryTable&lt;Data_##ClassName##&gt; where T : Data_##ClassName##, new()
    {
        /// &lt;summary&gt;
        /// 实例化对象
        /// &lt;/summary&gt;
        private T DataClass = new  T(); 

        /// &lt;summary&gt;
        /// 数据操作常用方法
        /// &lt;/summary&gt;
        private Tong.TongUse TextData = new TongUse();

            private string orderBy;
        /// &lt;summary&gt;
        /// 要初始化排序条件
        /// &lt;/summary&gt;
        public string OrderBy
        {
            get
            {
                return orderBy;
            }
            set
            {
                orderBy = value;
            }
        }

        private  string errorInfo=&quot;&quot;;
        /// &lt;summary&gt;
        /// 出错的信息
        /// &lt;/summary&gt;
        public string ErrorInfo
        {
            get
            {
                return errorInfo;
            }
            set
            {
                errorInfo = value;
            }
        }

        /// &lt;summary&gt;
        /// 用于实现插入的方法
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;更新的对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public bool Operate_inser(Data_##ClassName## t)
        {
             SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }
            //##Operate_inser##
            MySql.Close();
        }

        /// &lt;summary&gt;
        /// 更新数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;更新的对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public bool Operate_update(Data_##ClassName## t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }
            //##Operate_update##
            MySql.Close();
        }

        /// &lt;summary&gt;
        /// 传入 实例化的对象的主键值 此对象一定要指定主键
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;实例化的数据库表对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Operate_Select(Data_##ClassName## DataTable_Obj)
        {


                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;
                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_Obj##
                #endregion

                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;


        }
        /// &lt;summary&gt;
        /// 传入一个 ID 值 用于得这个ID 值下的所有 数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;ID&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string ID)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_ID##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }


        /// &lt;summary&gt;
        ///  传入字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string ID, string CoulmnName)
        {


                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_IDAndCoulmnName##
                #endregion


                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
        /// &lt;summary&gt;
        /// 字段名 返回一个字段的值 调用条数
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;ID&quot;&gt;字段名&lt;/param&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;调用条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string CoulmnName, int RecordNum)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_CoulmnNameAndRecordNum##

                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
        /// &lt;summary&gt;
        /// 传入字段集合 返回条数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段的数组  数组长度为0 为 得到全部的字段  &lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;得到记录的条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum)
        {
                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法

                string Cloumn = &quot;&quot;;
                for(int i=0;i&lt;CoulmnName.Length;i++)
                {
                    Cloumn+=CoulmnName[i].ToString()+&quot;,&quot;;
                }

                if(Cloumn!=&quot;&quot;)
                {
                    Cloumn = Cloumn.Substring(0,Cloumn.Length-1);
                }
                else
                {
                    Cloumn=&quot;*&quot;;
                }

                //##Operate_Operate_Select_CoulmnName[]AndRecordNum##

                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
            /// &lt;summary&gt;
        ///  传入多个字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string CoulmnName, int RecordNum, string Where)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_CoulmnNameAndRecordNum_Where##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }

            /// &lt;summary&gt;
        ///  传入字段集合 返回条数据
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到 字段的数组  数组长度为0 为 得到全部的字段&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum, string Where)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                 string Cloumn = &quot;&quot;;
                for(int i=0;i&lt;CoulmnName.Length;i++)
                {
                    Cloumn+=CoulmnName[i].ToString()+&quot;,&quot;;
                }

                if(Cloumn!=&quot;&quot;)
                {
                    Cloumn =  Cloumn.Substring(0,Cloumn.Length-1);
                }
                else
                {
                    Cloumn=&quot;*&quot;;
                }
                //##Operate_Operate_Select_CoulmnName[]AndRecordNum_where##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }


        #region 数据转对象

        /// &lt;summary&gt;
        ///  传入读出数据的条数 条件
        ///  返回 Data_CX_NEWS 类型的数组
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public Data_##ClassName##[] Oper_SelectToObject(int RecordNum, string Where)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum, Where));
        }

        /// &lt;summary&gt;
        ///  传入读出数据的条数 
        ///  返回 Data_CX_NEWS 类型的数组
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public Data_##ClassName##[] Oper_SelectToObject(int RecordNum)
        {
            return ConvertToObject(OperSelectN(new String[] { },RecordNum));
        }

        #endregion

        #region  用于实现数据转换成类型的方法

        /// &lt;summary&gt;
        /// 把对应表的数据转成对象
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;MyDs&quot;&gt;传入的dataset&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private Data_##ClassName##[] ConvertToObject(DataSet MyDs)
        {

            DataTable Mydt = MyDs.Tables[0];
            //当前的记录数，默认 为 0
            int Count = 0;
            //定义一个方法用于显示数据 类型的集合
            Data_##ClassName##[] p = new Data_##ClassName##[1];
            if (Mydt.Rows.Count == 0)
            {
                p = new Data_##ClassName##[1];
                Count = 1;
            }
            else
            {
                p = new Data_##ClassName##[Mydt.Rows.Count];
            }

            try
            {
                for (int i = 0; i &lt; Mydt.Rows.Count; i++)
                {
                    Data_##ClassName## Mydato = new Data_##ClassName##();
                    #region 实现转换的方法
                        //##ConvertToObject##
                    #endregion 
                    p[i] = Mydato;
                }
            }
            catch (Exception ex)
            {
                errorInfo += &quot;执行  把对应表的数据转成对象时出现错误&quot; + ex.Message + ex.Source;
            }
            if (Count != 0)
            {
                p[0] = new Data_##ClassName##();

            }

            return p;


        }
        #endregion


        /// &lt;summary&gt;
        /// 执行SQL语句 返回dataSet
        /// &lt;/summary&gt;
        /// &lt;typeparam name=&quot;Tab&quot;&gt;数据表&lt;/typeparam&gt;
        /// &lt;param name=&quot;Sql&quot;&gt;执行的SQL&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet ExecuteQuery(string Sql)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_Sql##
                #endregion



                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }

    }

    #endregion</textarea></p>
  <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine">#region 定义类型 定义类型  ##ClassName##  的操作方法 
    /// &lt;summary&gt;
    /// 用于对相应表 ##ClassName## 进行操作的类弄
    /// &lt;/summary&gt;
    /// &lt;typeparam name=&quot;T&quot;&gt;表类型对象&lt;/typeparam&gt;
    [System.ComponentModel.DataObject]
    public class Data_##ClassName##_QueryTable&lt;T&gt; : DataIQueryTable&lt;Data_##ClassName##&gt; where T : Data_##ClassName##, new()
    {
        /// &lt;summary&gt;
        /// 实例化对象
        /// &lt;/summary&gt;
        private T DataClass = new  T(); 

        /// &lt;summary&gt;
        /// 数据操作常用方法
        /// &lt;/summary&gt;
        private Tong.TongUse TextData = new TongUse();

            private string orderBy;
        /// &lt;summary&gt;
        /// 要初始化排序条件
        /// &lt;/summary&gt;
        public string OrderBy
        {
            get
            {
                return orderBy;
            }
            set
            {
                orderBy = value;
            }
        }

        private  string errorInfo=&quot;&quot;;
        /// &lt;summary&gt;
        /// 出错的信息
        /// &lt;/summary&gt;
        public string ErrorInfo
        {
            get
            {
                return errorInfo;
            }
            set
            {
                errorInfo = value;
            }
        }

        /// &lt;summary&gt;
        /// 用于实现插入的方法
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;更新的对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public bool Operate_inser(Data_##ClassName## t)
        {
             SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }
            //##Operate_inser##
            MySql.Close();
        }

        /// &lt;summary&gt;
        /// 更新数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;更新的对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public bool Operate_update(Data_##ClassName## t)
        {
            SqlConnection MySql = new SqlConnection(TextData.SqlConnStr);
            if (MySql.State == ConnectionState.Closed)
            {
                MySql.Open();
            }
            //##Operate_update##
            MySql.Close();
        }

        /// &lt;summary&gt;
        /// 传入 实例化的对象的主键值 此对象一定要指定主键
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;t&quot;&gt;实例化的数据库表对象&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Operate_Select(Data_##ClassName## DataTable_Obj)
        {


                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;
                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_Obj##
                #endregion

                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;


        }
        /// &lt;summary&gt;
        /// 传入一个 ID 值 用于得这个ID 值下的所有 数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;ID&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string ID)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_ID##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }


        /// &lt;summary&gt;
        ///  传入字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string ID, string CoulmnName)
        {


                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_IDAndCoulmnName##
                #endregion


                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
        /// &lt;summary&gt;
        /// 字段名 返回一个字段的值 调用条数
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;ID&quot;&gt;字段名&lt;/param&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;调用条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string CoulmnName, int RecordNum)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_CoulmnNameAndRecordNum##

                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
        /// &lt;summary&gt;
        /// 传入字段集合 返回条数据
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段的数组  数组长度为0 为 得到全部的字段  &lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;得到记录的条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum)
        {
                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法

                string Cloumn = &quot;&quot;;
                for(int i=0;i&lt;CoulmnName.Length;i++)
                {
                    Cloumn+=CoulmnName[i].ToString()+&quot;,&quot;;
                }

                if(Cloumn!=&quot;&quot;)
                {
                    Cloumn = Cloumn.Substring(0,Cloumn.Length-1);
                }
                else
                {
                    Cloumn=&quot;*&quot;;
                }

                //##Operate_Operate_Select_CoulmnName[]AndRecordNum##

                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }
            /// &lt;summary&gt;
        ///  传入多个字段名得到这个字段在表里的记录,只有一个字段 
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet Oper_Select(string CoulmnName, int RecordNum, string Where)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_CoulmnNameAndRecordNum_Where##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }

            /// &lt;summary&gt;
        ///  传入字段集合 返回条数据
        ///  返回 DataSet
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;CoulmnName&quot;&gt;字段名  能在表里找到 字段的数组  数组长度为0 为 得到全部的字段&lt;/param&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet OperSelectN(string[] CoulmnName, int RecordNum, string Where)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                 string Cloumn = &quot;&quot;;
                for(int i=0;i&lt;CoulmnName.Length;i++)
                {
                    Cloumn+=CoulmnName[i].ToString()+&quot;,&quot;;
                }

                if(Cloumn!=&quot;&quot;)
                {
                    Cloumn =  Cloumn.Substring(0,Cloumn.Length-1);
                }
                else
                {
                    Cloumn=&quot;*&quot;;
                }
                //##Operate_Operate_Select_CoulmnName[]AndRecordNum_where##
                #endregion




                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }


        #region 数据转对象

        /// &lt;summary&gt;
        ///  传入读出数据的条数 条件
        ///  返回 Data_CX_NEWS 类型的数组
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;param name=&quot;Where&quot;&gt;条件 如 newsid!=&quot;&quot; and 0=0 &lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public Data_##ClassName##[] Oper_SelectToObject(int RecordNum, string Where)
        {
            return ConvertToObject(OperSelectN(new String[] { }, RecordNum, Where));
        }

        /// &lt;summary&gt;
        ///  传入读出数据的条数 
        ///  返回 Data_CX_NEWS 类型的数组
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;RecordNum&quot;&gt;读出条数&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public Data_##ClassName##[] Oper_SelectToObject(int RecordNum)
        {
            return ConvertToObject(OperSelectN(new String[] { },RecordNum));
        }

        #endregion

        #region  用于实现数据转换成类型的方法

        /// &lt;summary&gt;
        /// 把对应表的数据转成对象
        /// &lt;/summary&gt;
        /// &lt;param name=&quot;MyDs&quot;&gt;传入的dataset&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        private Data_##ClassName##[] ConvertToObject(DataSet MyDs)
        {

            DataTable Mydt = MyDs.Tables[0];
            //当前的记录数，默认 为 0
            int Count = 0;
            //定义一个方法用于显示数据 类型的集合
            Data_##ClassName##[] p = new Data_##ClassName##[1];
            if (Mydt.Rows.Count == 0)
            {
                p = new Data_##ClassName##[1];
                Count = 1;
            }
            else
            {
                p = new Data_##ClassName##[Mydt.Rows.Count];
            }

            try
            {
                for (int i = 0; i &lt; Mydt.Rows.Count; i++)
                {
                    Data_##ClassName## Mydato = new Data_##ClassName##();
                    #region 实现转换的方法
                        //##ConvertToObject##
                    #endregion 
                    p[i] = Mydato;
                }
            }
            catch (Exception ex)
            {
                errorInfo += &quot;执行  把对应表的数据转成对象时出现错误&quot; + ex.Message + ex.Source;
            }
            if (Count != 0)
            {
                p[0] = new Data_##ClassName##();

            }

            return p;


        }
        #endregion


        /// &lt;summary&gt;
        /// 执行SQL语句 返回dataSet
        /// &lt;/summary&gt;
        /// &lt;typeparam name=&quot;Tab&quot;&gt;数据表&lt;/typeparam&gt;
        /// &lt;param name=&quot;Sql&quot;&gt;执行的SQL&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public DataSet ExecuteQuery(string Sql)
        {

                SqlDataAdapter MyDa = new SqlDataAdapter(&quot;&quot;,TextData.SqlConnStr);
                MyDa.SelectCommand.Connection = TextData.MySql;
                MyDa.SelectCommand.CommandType = CommandType.Text;

                #region ##ClassName## 的查询方法
                //##Operate_Operate_Select_Sql##
                #endregion



                DataSet MyDs = new DataSet();
                try
                {
                    MyDa.Fill(MyDs);
                }
                catch (Exception ex)//資料填充時的異常處理
                {
                    if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                    {
                        TextData.MySql.Close();
                    }
                    MyDs = null;
                    ErrorInfo+=&quot;执行查询操作ExecuteQuery(string Sql)时出现错误&quot;+ex.Message;

                }

                if (TextData.MySql.State == ConnectionState.Open)///ConnectionState 得到當前資料源聯接的狀態
                {
                    TextData.MySql.Close();

                }
                return MyDs;
        }

    }

    #endregion</asp:TextBox>
  
  </p>
</form>
    </body>
</html>
